<?php

class Sistema_Form_Matricula extends Zend_Form
{

    public function init()
    {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        if($controller == 'filamatricula'){      
            $url .= '/matriculas/cur_id/'.$front->getRequest()->getParam('cur_id');
        }
        
        $id = $front->getRequest()->getParam('id', 0);
        
        $this->setName('form_'.$controller);
        
        Zend_Loader::loadClass('dominio','library');
        Zend_Loader::loadClass('operacoes','library');
        
        
        $el = new Zend_Form_Element_Hidden('MAT_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))->addFilter('Int');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Hidden('USU_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))->addFilter('Int');
        $el->setValue(Zend_Auth::getInstance()->getStorage()->read()->USU_ID);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('USU_NOM');
        $el->setLabel('Matriculador');
        $el->setAttrib('readonly',true);
        $el->setValue(Zend_Auth::getInstance()->getStorage()->read()->USU_NOME);
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Hidden('ALU_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int')
            ->setAttrib('class', 'ajx_vlr_id find_alu_id')
            ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ALU_NOM');
        $el->setLabel('Aluno');
        if($id == 0) $el->setDescription('<a href="javascript:void(0)" class="ajx_img clk_sel_alu"></a>');
        $el->setDecorators(array('ViewHelper',
        array('Description', array('escape' => false, 'tag' => false)),
        array('HtmlTag', array('tag' => 'dd')),
        array('Label', array('tag' => 'dt')),
        'Errors',))
        ->setRequired(true)
        ->setAttrib('class', 'ajx_vlr_nom find_alu_nom')
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        if($id > 0) $el->setAttrib('readonly',true);
        $this->addElement($el);
        
        
        $obj = new Sistema_Model_DbTable_Curso();
        $row = $obj->fetchAll('CUR_STA = 1 and CUR_ANO >= '.date('Y'))->toArray();
        $arr = array('0'=>'Nenhum');
        foreach($row as $r) 
        {
            $arr[$r['CUR_ID']] = $r['CUR_NOM'] .', Turno: '. dominio::getTurno($r['TUR_ID']). ', Turma:'.$r['CUR_TRM']. ', Qtd: '.Operacoes::vagasCurso($r['CUR_ID']) .' / '.  $r['CUR_NMRMAXALU'];
        }
        
        $el = new Zend_Form_Element_Select('CUR_ID',array('onchange' => ''));
        $el->setLabel('Curso')
        ->setAttrib('class','curso')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr);
        if($id > 0) $el->setAttrib('disabled',true);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MAT_VLRENT');
        $el->setLabel('Valor Entrada');
        $el->setAttrib('class','valor');
        if($id > 0) $el->setAttrib('readonly',true);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_VLR');
        $el->setLabel('Valor Curso');
        $el->setAttrib('readonly',true);
        $el->setAttrib('class','valor cur_val');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Text('CUR_VLRPRO');
        $el->setLabel('Valor Promocional')
        ->setAttrib('readonly',true)
        ->setAttrib('class','valor cur_valpro')
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MAT_VLRDIR');
        $el->setLabel('Valor Diferenciado');
        if($id == 0) $el->setDescription('<a href="javascript:void(0)" class="clk_lib_aces">LIBERAR VALOR</a><input id="_user" name="_user" type="hidden" value="" /><input id="_key" name="_key" type="hidden" value="" />');
        $el->setDecorators(array('ViewHelper',
        array('Description', array('escape' => false, 'tag' => false)),
        array('HtmlTag', array('tag' => 'dd')),
        array('Label', array('tag' => 'dt')),
        'Errors',))
        ->setAttrib('readonly',true)
        ->setAttrib('class','valor cur_valbol')
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        
        $obj = new Sistema_Model_DbTable_Formaspagamento();
        $row = $obj->fetchAll()->toArray();
        $arr = array(''=>'Nenhum');
        foreach($row as $r) $arr[$r['FOR_ID']] = $r['FOR_NOM']; 
                
        $el = new Zend_Form_Element_Select('FOR_ID',array('onchange' => ''));
        $el->setLabel('Forma de Pagamento')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr);
        $el->setAttrib('class','tam_med for_pag');
        if($id > 0) $el->setAttrib('disabled',true);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MAT_QTDPAR');
        $el->setLabel('Qtd de Parcelas');
        $el->setAttrib('readonly',true);
        $el->setAttrib('class','parcelas numero');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MAT_QTDPARDIR');
        $el->setLabel('Qtd de Parcelas - Diferenciado');
        $el->setAttrib('class','numero');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_PERDSC');
        $el->setLabel('Desconto à vista %');
        $el->setAttrib('readonly',true);
        $el->setAttrib('class','valor');
        $this->addElement($el);
        
        //$el = new Zend_Form_Element_Checkbox('MAT_STA',array('checked'=>'checked'));
        //$el->setLabel('Status');
        //if($id > 0) $el->setAttrib('disabled',true);
        //$this->addElement($el);
        
        if($id == 0){   
            $btn = new Zend_Form_Element_Submit('Salvar',array('disableLoadDefaultDecorators' =>true));
            $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
            $btn->setLabel('Salvar');
            $btn->setAttrib('id', 'submitbutton');
            $btn->setAttrib('class', 'btn-frm');
            $this->addElement($btn);
        }
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
    }


}



